package com.zhentao.controller;

import com.zhentao.common.constants.ArticleConstants;
import com.zhentao.file.service.FileStorageService;
import com.zhentao.service.ArticleService;
import com.zhentao.model.article.dto.ArticleHomeDto;
import com.zhentao.model.common.dtos.ResponseResult;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.FileInputStream;

@RestController
@RequestMapping("/api/v1/article")
public class ArticleHomeController {

    @Autowired
    private ArticleService articleService;
    @Autowired
    private FileStorageService fileStorageService;

    @SneakyThrows
    @GetMapping("/testMinio")
    public ResponseResult testMinio() {
        FileInputStream fileInputStream = new FileInputStream("D:\\list.html");;
        String path=fileStorageService.uploadHtmlFile("article","list.html",fileInputStream);
        return ResponseResult.okResult(path);
    }
    @PostMapping("/load")
    public ResponseResult load(@RequestBody ArticleHomeDto dto){
        //        return articleService.load(dto, ArticleConstants.LOADTYPE_LOAD_MORE);
        return articleService.load2(ArticleConstants.LOADTYPE_LOAD_MORE, dto,true);
    }

    @PostMapping("/loadmore")
    public ResponseResult loadMore(@RequestBody ArticleHomeDto dto) {
        return articleService.load(ArticleConstants.LOADTYPE_LOAD_MORE,dto);
    }

    @PostMapping("/loadnew")
    public ResponseResult loadNew(@RequestBody ArticleHomeDto dto) {
        return articleService.load(ArticleConstants.LOADTYPE_LOAD_NEW,dto);
    }
}
